<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

include_once("./thumb.php");
//이미지 썸네일 크기 설정
$img['width'] = "307";
$img['height'] = "92";
$image_quality = 90; //jpeg Quality 1~100까지 설정
$mod = 2;//$board[bo_gallery_cols];
$td_width = (int)(100 / $mod);
// 선택옵션으로 인해 셀합치기가 가변적으로 변함
$colspan = 5;
if ($is_checkbox)$colspan++;
if ($is_good)$colspan++;
if ($is_nogood)$colspan++;

?>
<?=subtitle("진행중인 이벤트")?>

<!-- 게시판 목록 -->
<div id='g4m_gallery' style='width:<?php echo $bo_table_width ?>; min-width: 600px;margin:0 auto;'>

    
    <form id='fboardlist' method='post' action='<?php echo $g4['bbs_path']; ?>/list_update.php'>
		<input type='hidden' name='bo_table' value='<?php echo $bo_table ?>' />
        <input type='hidden' name='sfl'  value='<?php echo $sfl ?>' />
        <input type='hidden' name='stx'  value='<?php echo $stx ?>' />
        <input type='hidden' name='spt'  value='<?php echo $spt ?>' />
        <input type='hidden' name='page' value='<?php echo $page ?>' />
        <div style="margin-top:10px"></div>
        <table style="width:100%" class="board_list" >
        <tr>
            <?
                $list_count = count($list);
                
                for ($i = 0; $i < $list_count; $i++) {
                    $date = date("y-m-d", strtotime($list[$i]['wr_datetime']));

					$thumb_number = ($list[$i][wr_10])? "".$list[$i][wr_10]."":"0";
					$file = $list[$i][file][0][path] .'/'. $list[$i][file][$thumb_number][file];
					// 업로드된 파일이 이미지라면
					if (preg_match("/\.(jpg|gif|png)$/i", $file) && file_exists($file)) {
							$thumb = thumbnail($file, $img['width'], $img['height'], 0, 1, $image_quality, 0, "",  $filter, $noimg); // 첨부 썸네일
						} else { //에디터에서 삽입한 이미지 라면
							$edit_img = $list[$i]['wr_content'];
							if (preg_match("/<img.*src=\\\"(.*)\\\"/iUs", stripslashes($edit_img), $tmp)) { // 에디터 이미지추출
								$file = str_replace($g4[url], "..",$tmp[1]); // 파일명
								if (is_file($file)) {
								$thumb = thumbnail($file, $img['width'], $img['height'], 0, 1, $image_quality, 0, "",  $filter, $noimg); // 에디터 썸네일
								}
							} else {
								$thumb = $board_skin_path."/img/noimage.gif";
							}
						}
					$img_tag = "<a href='{$list[$i]['href']}' class='img_link' style='display:block;width:{$img['width']}px;height:{$img['height']}px;background-color:#5f9200;'><img src='$thumb'  style='width:{$img['width']}px;height:{$img['height']}px' /></a>";
                    if ($i && $i % $mod == 0)
                        echo "</tr><tr>";
                    echo "<td style='width:{$td_width}%;padding-bottom:25px;padding-left:35px; vertical-align: top'>";
                    echo "<table style='width:100%'>";
                    echo "<tr><td style='text-align:center;'>";
                    ?>
                    <?php echo $img_tag;?>
					<style>
						.img_info img{vertical-align:middle;}
					</style>
                    <dl class="img_info" style="margin-top:5px;">
                        <dt>
                        <?
						$today = date("Y-m-d");
						if($list[$i]['wr_2'] >= $today) {
							$day_stat_img = "day_stat_ing"; //진행중
						} else {
							$day_stat_img = "day_stat_end"; //종료
						}
                        //if ($is_category && $list[$i]['ca_name'])
                            //echo "<span class=\"cate\"><a href='{$list[$i]['ca_name_href']}'>[{$list[$i][ca_name]}]</a></span> ";
						?>
						<img src="<?php echo $g4['path']?>/imgs/event/<?php echo $day_stat_img?>.png" />
						<?
                        echo "<a href=\"{$list[$i]['href']}\"><span style='color:#666;font-weight:bold'>{$list[$i]['subject']}</span></a>";
                        //if ($list[$i]['comment_cnt'])
                            //echo " <a href=\"{$list[$i]['comment_href']}\" class=\"comment\">{$list[$i]['comment_cnt']}</a>";

                        //echo $list[$i]['icon_new'] ? " " . $list[$i]['icon_new'] : "";
                        /*
                        echo $list[$i]['icon_file'] ? " " . $list[$i]['icon_file'] : "";
                        echo $list[$i]['icon_link'] ? " " . $list[$i]['icon_link'] : "";
                        echo $list[$i]['icon_hot'] ? " " . $list[$i]['icon_hot'] : "";
                        echo $list[$i]['icon_secret'] ? " " . $list[$i]['icon_secret'] : "";
                         */
                        $view_good = "";
                        if ($is_good)
                            $view_good = " <img width='1' height='7' alt='|' src='$board_skin_path/img/line_s.gif' /> <span style='color:#0033ff'>Good {$list[$i]['wr_good']}</span>";
                        $view_chkbox="";
                        if ($is_checkbox)
                            $view_chkbox = " <input type='checkbox' name='chk_wr_id[]' value='{$list[$i]['wr_id']}' style='margin:0;padding:0;line-height:0; font-size:0;vertical-middle:middle' />";
                        ?>
                        </dt>
                        <dd>이벤트기간 : <?php echo $list[$i]['wr_1']?> ~ <?php echo $list[$i]['wr_2']?> <?php echo $view_chkbox?></dd>
                    </dl>
                <?
                    echo "</td></tr>";
                    echo "</table></td>\n";
            } // for()
         
                // 나머지 td
                $cnt = $i % $mod;
                if ($cnt)
                    for ($i = $cnt; $i < $mod; $i++)
                        echo "<td width='{$td_width}%'>&nbsp;</td>";
            ?>
                    </tr>
                    <!-- <tr><td colspan=<?php echo $mod?> height=1 bgcolor=#E7E7E7></td></tr> -->

                    <? if (count($list) == 0) { echo "<tr><td colspan='$mod' class='nodata'>게시물이 없습니다.</td></tr>"; } ?>
                    <!-- <tr><td colspan=<?php echo $mod?> bgcolor=#5C86AD height=1> -->
                </table>
        <?php if ($is_checkbox) { ?>
        <div class="board_sw">
            <span>선택한 글들을</span>
            <select name="sw">
                <option value="delete">삭제</option>
                <option value="copy">복사</option>
                <option value="move">이동</option>
            </select>
            <span>합니다.</span>
            <noscript><input type="submit" value="확인" /></noscript>
        </div>
        <?php } ?>

    </form>
    <div class='btn_area' >
        <div class='fl' >
			<?php if($is_admin) { ?>
            <a href="<?php echo $write_href ?>"><img src="<?php echo $board_skin_path ?>/img/btn_write.gif" alt="글쓰기" /></a>
			<? } ?>
           <!--  <? if ($is_checkbox) {?>
            <a href="javascript:select_sw('delete');"><img src="<?php echo $board_skin_path ?>/img/btn_select_delete.gif" alt="선택삭제" /></a>
            <a href="javascript:select_sw('copy');"><img src="<?php echo $board_skin_path ?>/img/btn_select_copy.gif" alt="선택복사" /></a>
            <a href="javascript:select_sw('move');"><img src="<?php echo $board_skin_path ?>/img/btn_select_move.gif" alt="선택이동" /></a>
            <? } ?>-->
        </div>
        <div class='fr'>
            <? if ($list_href) { ?><p><a href="<?php echo $list_href ?>"><img src="<?php echo $board_skin_path ?>/img/btn_list.gif" alt='' /></a></p><? } ?>
        </div>
    </div>

    <div class='page_area'>
    <? if ($prev_part_href) {echo "<a href='$prev_part_href'><img src='$board_skin_path/img/page_search_prev.gif' alt='' title='이전검색' /></a>";} ?>
    <?php echo str_replace(" &nbsp;", " ",$write_pages); ?>
    <? if ($next_part_href) {
            echo "<a href='$next_part_href'><img src='$board_skin_path/img/page_search_next.gif' alt='' title='다음검색' /></a>";
    } ?>
    </div>

    <div class='search_area'>
        <form id='fsearch' method='get' action='<?php echo $_SERVER[PHP_SELF] ?>'>
            <div>
                <input type='hidden' name='bo_table' value='<?php echo $bo_table ?>' />
                <input type='hidden' name='sca'      value='<?php echo $sca ?>' />
                <input type='hidden' name='sop'      value='<?php echo $sop ?>' />
                <select name='sfl' class='sel_search'>
                    <option value='wr_subject||wr_content'>제목+내용</option>
                    <option value='wr_subject'>제목</option>
                    <option value='wr_content'>내용</option>
                    <option value='mb_id,1'>회원아이디</option>
                    <option value='mb_id,0'>회원아이디(코)</option>
                    <option value='wr_name,1'>글쓴이</option>
                    <option value='wr_name,0'>글쓴이(코)</option>
                </select>
                <input type='text' name='stx' id='stx' size='20' maxlength='20' class='text' value='<?php echo stripslashes($stx) ?>' />
                <select name='sop' class='sel_search'>
                    <option value='and'>and</option>
                    <option value='or'>or</option>
                </select>
                <input type='image' src='<?php echo $g4['path']?>/imgs/event/btn_search.gif' class='btn_search' style="vertical-align:middle" />
            <!-- <label title='두개이상의 단어를 모두 포함하는 게시물을 검색'><input type='radio' name='sop' value='and' id='sop_and' /> and</label>
            <label title='하나의 단어라도 포함하는 게시물을 검색'><input type='radio' name='sop' value='or' id='sop_or' /> or</label> -->
            </div>
        </form>
    </div><!-- .board_search -->
</div><!-- #g4m_gallery-->
<br /><br /><br /><br /><br /><br /><br /><br />
<script type="text/javascript">
    //<![CDATA[
    function select_sw(sw) {
        var frm =$("#fboardlist");
        var opt = frm.find("select[name='sw'] > option[value='" + sw + "']");
        var str = opt.text();
        if(!frm.find("input[name='chk_wr_id[]']:checked").length) {
            alert(str + "할 게시물을 하나 이상 선택하세요.");
            return;
        }
        switch (sw) {
            case "copy" :
            case "move" :
                var sub_win = window.open("", "move", "left=50, top=50, width=500, height=550, scrollbars=1");
                frm.attr("target", "move");
                // frm.attr("action", "./move.php");
                break;
            case "delete" :
                if (!confirm("선택한 게시물을 정말 " + str + " 하시겠습니까?\n\n한번 " + str + "한 자료는 복구할 수 없습니다"))
                    return;
                // frm.attr("action", "./delete_all.php?" + Math.random());
                break;
            default :
                alert("지정되지 않은 작업입니다!");
                return false;
                break;
        }
        opt.attr("selected", "true");
        frm.submit();
    }

    $(function() {
        $("#board_sca").bind("change", function() {
            document.location.href = "./board.php?bo_table=" + g4_bo_table + "&sca=" + encodeURIComponent(this.value);
        }).val(g4_sca);

        // 배경색상 변경
        /*
        $("#img_list li")
        .each(function(i) {
            if (i%2==0)
                $(this).css("background", "#ffffff");
            else
                $(this).css("background", "#fcfcfc");
        })
        .bind("mouseover", function() {
            $(this).attr("rel", $(this).css("background"));
            $(this).css("background", "#f1f1f1");
        })
        .bind("mouseout", function() {
            $(this).css("background", $(this).attr("rel"));
        })
        */
        // 체크박스 모두 선택
        $("#all_chk").bind("click", function() {
            var chk = this.checked;
            $("#fboardlist input[name='chk_wr_id[]']").each(function() {
                this.checked = chk;
            });
        });

        $("#fsearch")
        .attr("autocomplete", "off")
        .load(function() {
            if ($(this).find("input[name='stx']").val()) {
                var val_sfl = $.trim($("#fboardlist input[name='sfl']").val());
                var val_sop = $.trim($(this).find("input[type='hidden'][name='sop']").val());
                if (val_sfl)
                    $(this).find("select[name=sfl] > option[value='" + val_sfl + "']").attr("selected", "true");
                if (val_sop) {
                    $(this).find("input[type='radio'][name='sop'][value='" + val_sop + "']").attr("checked", "checked");
                    $(this).find("select[name='sop'] > option[value='" + val_sop + "']").attr("selected", "true");
                }
            }
        })
        .submit(function() {
            var fld_stx= $(this).find("input[name='stx']");
            if (fld_stx.val().length < 2) {
                alert("검색어는 2글자 이상 입력하십시오.");
                fld_stx.select().focus();
                return false;
            }
        })
        .trigger("load");
    });
    //]]>
</script><!-- 게시판 목록 -->
